<?php

App::uses('AppModel', 'Model');

class Rule extends AppModel {
	
	public $useTable = false;
	
	public function all(){
	    $rules = $this->Session->read('rules');
	    
	    if (empty($rules)) {
	        $rules = array();
	        
	        if ($dir = opendir($this->rulesPath)) {
	            while ($f = readdir($dir)) {
	                if (preg_match('/\.php$/', $f)) {
	                    $className = preg_replace('/\.php$/', '', $f);
	                    App::uses($className, 'Lib' . DS . 'Rules');
	                    $vars = get_class_vars($className);
	                    
	                    $rules[] = array(
	                    	'name'      => $className,
                            'arguments' => $vars['arguments']
	                    );
	                }
	            }
	        }
	        //TODO: uncomment this: $this->Session->write('rules', $rules);
	    }
	    
	    return $rules;
	}
	
}

?>